package client;

import java.util.Random;

import simulation.SimulationConstants;

import entities.Location;

public class MovementSimulator {
	private Random random;
	
	public MovementSimulator(){
		random = new Random();
	}
	
	public void move(Location loc){
		double t = random.nextGaussian();
		t = Math.max(t, -1);
		t = Math.min(t, 1);
		
		double movmentLat = t / SimulationConstants.MOVMENT_SCALING;
		
		t = random.nextGaussian();
		t = Math.max(t, -1);
		t = Math.min(t, 1);
		double movmentLon = t / SimulationConstants.MOVMENT_SCALING;
		
		double latitude = loc.getLatitude() + movmentLat;
		latitude = Math.min(latitude, SimulationConstants.MAX_LATTITUDE);
		latitude = Math.max(latitude, SimulationConstants.MIN_LATTITUDE);
		loc.setLatitude(latitude);
		
		double longitude = loc.getLongitude() + movmentLon;
		longitude = Math.min(longitude, SimulationConstants.MAX_LONGITUDE);
		longitude = Math.max(longitude, SimulationConstants.MIN_LONGITUDE);
		loc.setLongitude(longitude);
	}
	
	public Location generateLocation(){
		double t = random.nextDouble();
		// A + t(B-A)
		double lat = SimulationConstants.MIN_LATTITUDE + t * (SimulationConstants.MAX_LATTITUDE - SimulationConstants.MIN_LATTITUDE) ;
		t = random.nextDouble();
		double lon =  SimulationConstants.MIN_LONGITUDE + t * (SimulationConstants.MAX_LONGITUDE - SimulationConstants.MIN_LONGITUDE) ;
		return new Location(lat, lon);
	}

}
